//
//  MyShipmentNumberCell.m
//  ReceiptDelivery
//
//  Created by 吕晶 on 2020/10/26.
//  Copyright © 2020 吕晶. All rights reserved.
//

#import "MyShipmentNumberCell.h"

@interface MyShipmentNumberCell ()

@property (nonatomic, strong) UIView *bgView;
@property (nonatomic, strong) UILabel *noTitleLab;
@property (nonatomic, strong) UILabel *noLab;
@property (nonatomic, strong) UIButton *erWeiMaBtn;
@property (nonatomic, strong) UILabel *chengYunTitleLab;
@property (nonatomic, strong) UILabel *chengYunLab;
@property (nonatomic, strong) UIButton *phoneBtn;

@end

@implementation MyShipmentNumberCell

+ (instancetype)MyShipmentNumberCellWithTableView:(UITableView *)tableView {
    static NSString *cellID = @"MyShipmentNumberCell";
    MyShipmentNumberCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
    if (cell == nil) {
        cell = [[MyShipmentNumberCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];
    }
    return cell;
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        self.backgroundColor = Color_backgroundColor;
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        
        self.bgView = [UIView new];
        self.bgView.backgroundColor = HexColor(0xffffff);
        self.bgView.layer.masksToBounds = YES;
        self.bgView.layer.cornerRadius = 6;
        [self.contentView addSubview:self.bgView];
        
        self.noTitleLab = [UILabel new];
        self.noTitleLab.textColor = HexColor(0x9C9DB3);
        self.noTitleLab.font = [UIFont systemFontOfSize:14];
        [self.bgView addSubview:self.noTitleLab];
        
        self.noLab = [UILabel new];
        self.noLab.textColor = HexColor(0x2B2C44);
        self.noLab.font = BoldFontOfSize(14);
        self.noLab.textAlignment = NSTextAlignmentRight;
        [self.bgView addSubview:self.noLab];
        
        self.erWeiMaBtn = [UIButton new];
        [self.bgView addSubview:self.erWeiMaBtn];
        
        self.chengYunTitleLab = [UILabel new];
        self.chengYunTitleLab.textColor = HexColor(0x9C9DB3);
        self.chengYunTitleLab.font = [UIFont systemFontOfSize:14];
        [self.bgView addSubview:self.chengYunTitleLab];
        
        self.chengYunLab = [UILabel new];
        self.chengYunLab.textColor = HexColor(0x2B2C44);
        self.chengYunLab.font = [UIFont systemFontOfSize:14];
        [self.bgView addSubview:self.chengYunLab];
        
        self.phoneBtn = [UIButton new];
        [self.phoneBtn addTarget:self action:@selector(phoneClick) forControlEvents:UIControlEventTouchUpInside];
        [self.bgView addSubview:self.phoneBtn];
    }
    return self;
}

- (void)phoneClick {
    if (self.model.tlogistics_mobile.length) {
        NSString *str = [[NSMutableString alloc] initWithFormat:@"tel:%@",self.model.tlogistics_mobile];
        [[UIApplication sharedApplication] openURL:[NSURL URLWithString:str] options:@{} completionHandler:nil];
    }
}

-(void)setModel:(WaybillMainModel *)model {
    _model = model;
    [self configUI];
}

- (void)configUI {
    self.bgView.nim_left = 15;
    self.bgView.nim_top = 10;
    self.bgView.nim_width = ScreenW - 2 * self.bgView.nim_left;
    
    self.noTitleLab.text = @"运单号：";
    self.noTitleLab.nim_left = 15;
    self.noTitleLab.nim_top = 20;
    [self.noTitleLab sizeToFit];
    
    self.noLab.text = self.model.wa_num;
    [self.noLab sizeToFit];
    self.noLab.nim_left = self.noTitleLab.nim_right;
    self.noLab.nim_centerY = self.noTitleLab.nim_centerY;
    
    self.erWeiMaBtn.nim_left = self.noLab.nim_right + 6;
    self.erWeiMaBtn.nim_width = 18;
    self.erWeiMaBtn.nim_height = 18;
    self.erWeiMaBtn.nim_centerY = self.noLab.nim_centerY;
    [self.erWeiMaBtn setImage:[UIImage imageNamed:@"icon_ladingbill_erweima"] forState:0];
    
    self.chengYunTitleLab.text = @"承运方：";
    self.chengYunTitleLab.nim_left = 15;
    self.chengYunTitleLab.nim_top = self.noTitleLab.nim_bottom + 15;
    [self.chengYunTitleLab sizeToFit];
    
    self.chengYunLab.text = self.model.tlogistics_name;
    [self.chengYunLab sizeToFit];
    self.chengYunLab.nim_left = self.chengYunTitleLab.nim_right;
    self.chengYunLab.nim_width = self.bgView.nim_width - 15 - 10 - 30 - self.chengYunLab.nim_left;
    self.chengYunLab.nim_centerY = self.chengYunTitleLab.nim_centerY;
    
    self.phoneBtn.nim_width = 30;
    self.phoneBtn.nim_height = 30;
    self.phoneBtn.nim_left = self.chengYunLab.nim_right + 10;
    self.phoneBtn.nim_centerY = self.chengYunTitleLab.nim_centerY;
    [self.phoneBtn setImage:[UIImage imageNamed:@"wofayun_phone_btn"] forState:0];
    
    self.bgView.nim_height = self.chengYunTitleLab.nim_bottom + 20;
    
    self.height = self.bgView.nim_bottom;
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
